package dao;

import java.util.LinkedList;
import java.util.List;

import entities.Administrator;
import entities.Cart;

public class CartDAO 
{

	private static final CartDAO instance = new CartDAO();
	private List<Cart> carts;
	
	private CartDAO(){
		carts = new LinkedList<Cart>();
		Cart cart = null;
	
		
		cart = Cart.newInstance("Let Go","images/mvstore_21.gif", 1, "12.99", "ADD");
		carts.add(cart);
		cart = Cart.newInstance("Forty Licks","images/mvstore_3.gif", 1, "12.99", "ADD");
		carts.add(cart);
		cart = Cart.newInstance("Charmbrace","images/mvstore_25.gif", 1, "12.99", "ADD");
		carts.add(cart);
	}
	
	public static CartDAO getInstance() {
		return instance;
	}

	public synchronized Cart findCart(String title) {
		Cart result = null;
		for (Cart s : carts){
			if (s.getTitle().equals(title)){
				result = s;
			}
		}
		return result;
	}

	public synchronized void addCart(Cart obj) throws RecordDuplicateException{
		if (findCart(obj.getTitle()) != null){
			throw new RecordDuplicateException("Customer with id: " + obj.getTitle() + " is already in the db.");
		}
		else {
			carts.add(obj);
		}
	}
}
